package com.app.mingluxing.bean;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.ArrayList;

/**
 * 群设置的bean
 * Created by Aaron on 16/2/22.
 */
public class GroupSettingBean implements Parcelable {

    public TopicEntity topic;

    public int code;
    public String code_msg;

    public static class TopicEntity implements Parcelable {

        //        public String _id;
        public String topic;
        //        public int __v;
//        public long lastTime;
//        public int type;
        public String groupImgUrl;
        public String groupName;
//        public List<String> history; //

        public ArrayList<UserListEntity> userList;

        public static class UserListEntity implements Parcelable {

            public UserEntity user;
            public String _id;
            //   public String sortLetters;  //显示数据拼音的首字母
            public boolean isAdmin;
            public boolean isSelect;


            @Override
            public int describeContents() {
                return 0;
            }

            @Override
            public void writeToParcel(Parcel dest, int flags) {
                dest.writeParcelable(this.user, flags);
                dest.writeString(this._id);
//                dest.writeString(this.sortLetters);
                dest.writeByte(isAdmin ? (byte) 1 : (byte) 0);
                dest.writeByte(isSelect ? (byte) 1 : (byte) 0);
            }

            public UserListEntity() {
            }

            protected UserListEntity(Parcel in) {
                this.user = in.readParcelable(UserEntity.class.getClassLoader());
                this._id = in.readString();
//                this.sortLetters = in.readString();
                this.isAdmin = in.readByte() != 0;
                this.isSelect = in.readByte() != 0;
            }

            public static final Creator<UserListEntity> CREATOR = new Creator<UserListEntity>() {
                @Override
                public UserListEntity createFromParcel(Parcel source) {
                    return new UserListEntity(source);
                }

                @Override
                public UserListEntity[] newArray(int size) {
                    return new UserListEntity[size];
                }
            };
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
//            dest.writeString(this._id);
            dest.writeString(this.topic);
//            dest.writeInt(this.__v);
//            dest.writeLong(this.lastTime);
//            dest.writeInt(this.type);
            dest.writeString(this.groupImgUrl);
            dest.writeString(this.groupName);
//            dest.writeStringList(this.history);
            dest.writeTypedList(userList);
        }

        public TopicEntity() {
        }

        protected TopicEntity(Parcel in) {
//            this._id = in.readString();
            this.topic = in.readString();
//            this.__v = in.readInt();
//            this.lastTime = in.readLong();
//            this.type = in.readInt();
            this.groupImgUrl = in.readString();
            this.groupName = in.readString();
//            this.history = in.createStringArrayList();
            this.userList = in.createTypedArrayList(UserListEntity.CREATOR);
        }

        public static final Creator<TopicEntity> CREATOR = new Creator<TopicEntity>() {
            public TopicEntity createFromParcel(Parcel source) {
                return new TopicEntity(source);
            }

            public TopicEntity[] newArray(int size) {
                return new TopicEntity[size];
            }
        };
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(this.topic, 0);
        dest.writeInt(this.code);
        dest.writeString(this.code_msg);
    }

    public GroupSettingBean() {
    }

    protected GroupSettingBean(Parcel in) {
        this.topic = in.readParcelable(TopicEntity.class.getClassLoader());
        this.code = in.readInt();
        this.code_msg = in.readString();
    }

    public static final Creator<GroupSettingBean> CREATOR = new Creator<GroupSettingBean>() {
        public GroupSettingBean createFromParcel(Parcel source) {
            return new GroupSettingBean(source);
        }

        public GroupSettingBean[] newArray(int size) {
            return new GroupSettingBean[size];
        }
    };
}
